package com.eas.web.common.chart;

import java.util.LinkedList;
import java.util.List;

import org.apache.commons.lang.StringUtils;

public class StackBarChart {

    private String type = "stack_bar";

    private List<KeyNode> keys;

    private List<StackValueArray> values;

    private List<String> xAxisLabels;

    private String titleText;

    private int yAxisMax;

    private int yAxisSteps;

    public StackBarChart() {
        this.keys = new LinkedList<KeyNode>();
        this.values = new LinkedList<StackValueArray>();
        this.xAxisLabels = new LinkedList<String>();
    }

    public void setTitleText(String text) {
        this.titleText = text;
    }

    public void addValueArray(StackValueArray valueArray) {
        values.add(valueArray);
    }

    public void addKey(KeyNode keyNode) {
        keys.add(keyNode);
    }

    public void addXaxisLabel(String label) {
        if (label != null) {
            xAxisLabels.add("\"" + label + "\"");
        }
    }

    public String renderValues() {
        StringBuilder sb = new StringBuilder();
        sb.append("[");
        sb.append(StringUtils.join(values, ","));
        sb.append("]");
        return sb.toString();
    }

    public String renderKeys() {
        StringBuilder sb = new StringBuilder();
        sb.append("[");
        sb.append(StringUtils.join(keys, ","));
        sb.append("]");
        return sb.toString();
    }

    public String renderXaxisLabels() {
        StringBuilder sb = new StringBuilder();
        sb.append("[");
        sb.append(StringUtils.join(xAxisLabels, ","));
        sb.append("]");
        return sb.toString();
    }

    public String renderTitleText() {
        return titleText;
    }

    public String getType() {
        return type;
    }

    public int getyAxisMax() {
        return yAxisMax;
    }

    public void setyAxisMax(int yAxisMax) {
        this.yAxisMax = yAxisMax;
    }

    public int getyAxisSteps() {
        return yAxisSteps;
    }

    public void setyAxisSteps(int yAxisSteps) {
        this.yAxisSteps = yAxisSteps;
    }
}
